function View(contextPath,divContainer){
	if(contextPath&&divContainer){
		this.contextPath = contextPath;
		this.divContainer = divContainer;
		this.registerEvent();
	}
}

View.prototype.extendedDiv = null;
View.prototype.functionId = null;

View.prototype.refresh = function(){
	this.divContainer.innerHTML = this.beforeRefresh();
	this.afterRefresh();
};

View.prototype.afterRefresh = function(){
};

View.prototype.beforeRefresh = function(){
	return "";
};

View.prototype.getDataArray = function(){
	var dataArray = [];
	if(this.dataModel){
		dataArray = this.dataModel["dataValues"]||dataArray;
	}
	return dataArray;
};

View.prototype.getTitleArray = function(){
	var titleArray = [];
	if(this.dataModel){
		titleArray = this.dataModel["titleValues"]||titleArray;
	}
	return titleArray;
};

View.prototype.getFooterArray = function(){
	var footerArray = [];
	if(this.dataModel){
		footerArray = this.dataModel["footerValues"]||footerArray;
	}
	return footerArray;
};

View.prototype.removeCache = function(cacheId){
	if(this.cacheObject){
		delete this.cacheObject[cacheId];
	}
	if(this.subComponents){
		for(var i=0;i<this.subComponents.length;i++){
			this.subComponents[i].removeCache(cacheId);
		}
	}
};

View.prototype.initExtendedDiv = function(){
	if(this.extendedDiv===null){
		var tempExtendedDiv = document.createElement("div");
		document.body.appendChild(tempExtendedDiv);
		tempExtendedDiv.style.position = "absolute";
		tempExtendedDiv.name = "extendeddiv";
		tempExtendedDiv.style.display = "none";
		tempExtendedDiv.style.border = "1px solid black";
		tempExtendedDiv.style.backgroundColor = "white";
		document.body.onclick = function(){
			var extendedDivArray = document.getElementsByTagName("div");
			for(var i=0;i<extendedDivArray.length;i++){
				if(extendedDivArray[i].name=="extendeddiv"){
					extendedDivArray[i].style.display = "none";
				}
			}
		};
		this.extendedDiv = tempExtendedDiv;
	}
};

View.prototype.hideExtendedDiv = function(focusedObject){
	focusedObject = focusedObject||this.extendedDiv;
	if(focusedObject){
		focusedObject.style.display = "none";
	}
};

View.prototype.showExtendedDiv = function(evt,focusedObject){
	if(this.extendedDiv){
		if(focusedObject){
			this.extendedDiv.style.left = focusedObject.offsetLeft;
			this.extendedDiv.style.top = focusedObject.offsetTop+focusedObject.offsetHeight+1;
		}else if(evt){
			this.extendedDiv.style.left = evt.clientX;
			this.extendedDiv.style.top = evt.clientY;
		}else{
			window["Comm"].showPopWindow(this.contextPath,"common.title.promptinfo","common.tip.noposition",null,null);
			return;
		}
		this.extendedDiv.style.width = "150px";
		this.extendedDiv.style.display = "block";
	}
};

View.prototype.showRightMenu = function(evt,focusedObject){
	if(this.functionId){
		var menuRequest = window["Comm"].buildRequestObject("query","*",null,"BAS_FUNCTION",null,"PARENTID='"+this.functionId+"'","GROUPING",null,null,null);
		var menu = new window["Menu"](this.contextPath,this.extendedDiv);
		menu.dataModel = window["Comm"].sendRequest(this.contextPath,menuRequest);
		if(menu.getDataArray().length>0){
			menu.refresh();
			if(this.menuClickHandler){
				menu.registerEventProcessor("afterClick0",this.menuClickHandler);
			}
			this.showExtendedDiv(evt,focusedObject);
		}
	}
};

View.prototype.registerEvent = function(){
	var eventNameArray = ["DblClick","Click","MouseOut","MouseOver","KeyUp","KeyDown","MouseUp"];
	var length = eventNameArray.length;
	for(var i=0;i<length;i++){
		this.divContainer["on"+eventNameArray[i].toLowerCase()] = (function(eventName,ins){return function(){ins.processEvent(eventName,window.event);};})(eventNameArray[i],this);
	}
};

View.prototype.processEvent = function(eventName,evt){
	var executeEventProcessor = function(eventKey,eventProcessorObject){
		var eventProcessorArray = eventProcessorObject[eventKey]||[];
		var length = eventProcessorArray.length;
		for(var i=0;i<length;i++){
			if(eventProcessorArray[i]){
				eventProcessorArray[i](evt);
			}
		}
	};
	this.eventProcessorObject = this.eventProcessorObject||{};
	executeEventProcessor("before"+eventName+evt.button,this.eventProcessorObject);
	if(this["handle"+eventName+"Event"+evt.button]){	
		var isCancelBubble = this["handle"+eventName+"Event"+evt.button](evt);
		if(isCancelBubble){
			evt.cancelBubble = true;
		}
	}
	executeEventProcessor("after"+eventName+evt.button,this.eventProcessorObject);
};

View.prototype.registerEventProcessor = function(eventName,funInstance){
	this.eventProcessorObject = this.eventProcessorObject||{};
	var eventProcessorArray = this.eventProcessorObject[eventName]||[];
	var find = false;
	var nullIndex = -1;
	for(var i=0;i<eventProcessorArray.length;i++){
		if(eventProcessorArray[i]==funInstance){
			find = true;
			break;
		}
		if(eventProcessorArray[i]===null){
			nullIndex = i;
		}
	}
	if(!find){
		if(nullIndex==-1){
			eventProcessorArray.push(funInstance);
		}else{
			eventProcessorArray[i] = funInstance;
		}
	}
	this.eventProcessorObject[eventName] = eventProcessorArray;
};
	
View.prototype.removeEventProcessor = function(eventName,funInstance){
	this.eventProcessorObject = this.eventProcessorObject||{};
	var eventProcessorArray = this.eventProcessorObject[eventName]||[];
	var length = eventProcessorArray.length;
	for(var i=0;i<length;i++){
		if(eventProcessorArray[i]==funInstance){
			eventProcessorArray[i] = null;
			break;
		}
	}
};
